|
|
|
|
|
|
|
specific to a form or modifies the properties of the form or its associated controls, you should probably place the procedure in the form itself. |
|
|
|
|
|
|
|
|
If, on the other hand, you are using the procedure with multiple forms in your program or have a generic procedure used by multiple programs, you should place it in a module. The storage location of your procedure is determined by where you create it. If you want, you can move a procedure from a form to a module or vice versa using cut-and-paste editing or even drag-and-drop editing. |
|
|
|
|
|
|
|
|
Storing a Procedure in a Form File |
|
|
|
|
|
|
|
|
To create a procedure in a form file, you just need to choose the form from the Project window and then access the code for the form. You do so either by double-clicking the form itself (or any control) or choosing the View Code button in the Project window (see Figure 11.4). After the Code window appears, you create a procedure as described in the earlier section ''Creating the Procedure." |
|
|
|
|
|
|
|
|
Figure 11.4
You can select a form for your
procedure from the Project window. |
|
|
|
|
|
|
|
|
Using a Module File for Procedures |
|
|
|
|
|
|
|
|
A module file contains only codeno form elements or events. If you already have a module file in your project, you can create a new procedure by selecting the file, opening the Code window, and then using the steps listed earlier to build the procedure. |
|
|
|
|
| |
|
|
|
|
Double-clicking the module name in the Project window automatically opens the Code window for the module. |
|
|
|
|
|
|
|
|
|
|
If you don't have a module file in your project, or if you want to use a new module, you can create a module by selecting Project, Add Module. You can also create a new module by clicking the arrow on the Add Form button in the toolbar and then choosing Module from the drop-down menu. Either way, you are presented with the Add Module dialog box; select the Module icon and click Open. A new module is created, and the Code window appears for you to begin editing. When you save your project or exit Visual Basic, you are asked for a filename for the module file. |
|
|
|
|
|